<template>
  <div>
    <header>订单管理</header>
    <div class="find">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item>
          <el-select v-model="formInline.listType" placeholder="按订单号查询">
            <el-option label="按订单号查询" value="按订单号查询"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-input v-model="formInline.orderNo" placeholder="订单号"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="content">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="orderNo" label="订单号"></el-table-column>
        <el-table-column prop="receiverName" label="收件人"></el-table-column>
        <el-table-column prop="statusDesc" label="订单状态"></el-table-column>
        <el-table-column prop="payment" label="订单总价"></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total"
        background
        class="pagination"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { orderList, searchOrder } from "../../util/netWork";
export default {
  data: () => ({
    formInline: {
      user: "",
      region: ""
    },
    tableData: [],
    currentPage: 1,
    pageSize: 10,
    pageNum: 1,
    total: 0
  }),
  mounted() {
    this.http();
  },
  methods: {
    http() {
      var data = {
        pageSize: this.pageSize,
        pageNum: this.pageNum
      };
      orderList(data)
        .then(res => {
          if (res.status == 0) {
            this.tableData = res.data.list;
            this.total = res.data.total;
            this.pagesize = res.data.pagesize;
          } else {
            console.log(res.msg);
          }
        })
        .catch(err => {
          console.log(err);
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      //   console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.http();
    },
    onSubmit() {
      var data = {
        listType: "search",
        pageNum: 1,
        orderNo: this.formInline.orderNo
      };
      searchOrder(data).then(res => {
        if (res.status == 0) {
          //   console.log(res);
          this.tableData = res.data.list;
        } else {
          console.log(res.msg);
        }
      });
    },
    handleClick(row) {
      this.$router.push({
        name: "OderInfo",
        params: {
          data: row
        }
      });
      //   console.log(row);
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/mixinScss.scss";
header {
  @include FontSize(30px);
  @include Size(100%, 100px);
  line-height: 100px;
  box-sizing: border-box;
  padding-left: 20px;
}
.pagination {
  @include Size(100%, 50px);
  text-align: center;
  @include Margin(20px, 0);
}
</style>